/**
 * @file:          SCurve.h
 * @brief:         
 * @details:       
 * @author:        wjh
 * @date created:  2023.06.20
 * @version:       1.0.0
 * @par copyright (c):
 *   
 * @par history (desc):
 *   version:1.0.0, wjh, 2023.06.20,09:35:13
 */


#ifndef SCURVE_H_
#define SCURVE_H_ 

#include "base_math.h"
#include "Datatype.h"

typedef struct SCurve
{
    float32 param_period_s;
    float32 param_speed_max;
    float32 param_acc_max;
    float32 param_jerk;

    float32 in_run_start;
    float32 in_pos_origin;
    float32 in_pos_target;

	int16 direction;
    uint16 running;
    float32 speed_max;
    float32 acc_max;
    float32 jerk;
    float32 displacement;
	uint8 traj_type;/* There are four types depending on SCurve setting paramter*/
    float32 traj_type_condition[4];
    uint16 current_section;

	float32 time_node_s[8];/* The time of each SCurve section */
	float32 time_delta_s[7];/* Duration of each section */

	float32 jerk_section[7];/* Jerk of each section */

	float32 section_pos_init[7];/* Displacement initial data of each sector */
	float32 section_spd_init[7];/* Speed initial data of each sector */
	float32 section_acc_init[7];/* Acceleration initial data of each sector */

	uint32 elapsed_time_count;
	float32 elapsed_time_s;
    float32 elapsed_time_section_s;

	/** Final output data */
    float32 out_run_finished;
	float32 out_pos;
	float32 out_spd;
	float32 out_acc;

    uint8 (*Init)(struct SCurve *self);
    void (*Planning)(struct SCurve *self);
    void (*Run)(struct SCurve *self);

} SCurve;


uint8 SCurve_Init(SCurve *self);
void SCurve_Planning(SCurve *self);

void SCurve_Run(SCurve *self);

#endif
